﻿﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<div class="modal-dialog x-modal-dialog" style="width:800px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb clearfix">

      <h2><i class="glyphicon glyphicon-fire" title="添加模版"></i>&nbsp;&nbsp;<span>添加模版</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/coupon-templates" data-validate="true">

      <div class="modal-body">
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">优惠券名称</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="name" data-validate="required" placeholder="请输入优惠券名称"/>
          </div>
          
          <label class="col-xs-2 control-label">折扣类型</label>
          <div class="pull-left" style="width: 30%">
            <select name="discountType" class="form-control select2" data-validate="required">
              <option value=""></option>
              <c:forEach var="couponTemplateDiscountType" items="${enums['couponTemplateDiscountType']}" >
                <option value="${couponTemplateDiscountType}">${couponTemplateDiscountType.description}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">可转赠</label>
          <div class="pull-left" style="width: 30%">
            <select name="giveAvailable" class="form-control select2" data-validate="required">
              <option value=""></option>
              <option value="false">否</option>
              <option value="true">是</option>
            </select>
          </div>
        </div>
        
        <div id="fixed_amount" class="form-group x-form-group hide">
          <label class="col-xs-2 control-label">面值</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="inputAmount" data-validate="required|float" placeholder="请输入面值" />
          </div>
          
          <label class="col-xs-2 control-label">最低消费金额</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="inputMinAmount" data-validate="required|float" placeholder="请输入最低消费金额" />
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">类型</label>
          <div class="pull-left" style="width: 30%">
            <select name="type" class="form-control select2" data-validate="required">
              <option value=""></option>
              <c:forEach var="couponTemplateType" items="${enums['couponTemplateType']}" >
                <option value="${couponTemplateType}">${couponTemplateType.description}</option>
              </c:forEach>
            </select>
          </div>
          
          <label class="product col-xs-2 control-label hide">产品名称</label>
          <div class="product pull-left hide" style="width: 30%">
            <select name="product.id" class="select2 form-control" data-validate="required">
              <option value=""></option>
              <c:forEach var="product" items="${persist.products}">
                <option value="${product.id}">${product.name}</option>
              </c:forEach>
            </select>
          </div>
          
          <label class="productType col-xs-2 control-label hide">类别名称</label>
          <div class="productType pull-left hide" style="width: 30%">
            <select name="productType" class="select2 form-control" data-validate="required">
              <option value=""></option>
              <c:forEach var="productType" items="${enums['productType']}">
                <option value="${productType}">${productType.description}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      </div>

      <div class="modal-footer clearfix">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script>

  $(function() {
    
    $('select[name="discountType"]').select2({
      placeholder : '请选择所属折扣类型',
      minimumResultsForSearch : -1,
      allowClear : false
    });
    
    $('select[name="giveAvailable"]').select2({
        placeholder : '请选择是否可转赠',
        minimumResultsForSearch : -1,
        allowClear : false
      });
    
    $('select[name="type"]').select2({
      placeholder : '请选择所属类型',
      minimumResultsForSearch : -1,
      allowClear : false
    });
    
    $('select[name="productType"]').select2({
      placeholder : '请选择产品类别',
      minimumResultsForSearch : -1,
      allowClear : true
    });
    
    $('select[name="product.id"]').select2({
      placeholder : '请选择所属产品',
      minimumResultsForSearch : -1,
      allowClear : true
    });
    
  })
</script>
